import GameUtil from '../../Fantasy/Util/GameUtil';
import ServerCenter from '../../Server/ServerCenter';
import PromptManage from '../PromptManage';
import SoundUtil from '../../Fantasy/Util/SoundUtil';
import JsbUtil from '../../Fantasy/Util/JsbUtil';
// Learn TypeScript:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.Node)
    easy: cc.Node = null;
    @property(cc.Node)
    middle: cc.Node = null;
    @property(cc.Node)
    high: cc.Node = null;

    diff = null;
    bookId = null;
    unit = null;
    part ;
    setRushInfo(diff,bookId,unit){
        this.diff = diff;
        this.bookId = bookId;
        this.unit = unit;
        switch(diff){
            case 'easy':
                this.easy.active = true;
                this.part = 1;
                break;
            case 'middle':
                this.middle.active = true;
                this.part = 2;
                break;
            case 'high':
                this.high.active = true;
                this.part = 3;
                break;
        }
    }
    btnCallback(target,data){
        SoundUtil.playEffect("music/click");
        if (data == 'close'){
            this.node.destroy();
        }
        else if (data == 'go'){
            let ste = ServerCenter.getUserStamina();
            if (ste >= 5){
                this.startGame();
                ServerCenter.addUserStamina(-5);
            }
            else{
                if(JsbUtil.checkCanVideo() == true){
                    PromptManage.addDialog('观看完整视频获得50点体力',2)
                }else {
                    PromptManage.addToast('您的体力值不够!')
                }
            }
        }
    }
    startGame(){
        let bookid = this.bookId;
        let unit = this.unit;
        let part = this.part;
        GameUtil.gotoScene('GameScene',()=>{
            cc.find('Canvas').getComponent('GameSceneJs').initBookUnitPart(bookid,unit,part);
        },true)
    }
}
